The present invention relates to a method and apparatus for handling texture and other attributes in rendering of graphic images composed of a plurality of triangular image primitives and particularly, but not exclusively, to the rendering of such images in a tile-based renderer, where those images are generated as a series of regular pixel blocks (tiles) assembled to form the full image.
A common operation in three-dimensional (3D) graphics is calculation of attribute values at various positions within a triangular image primitive based upon values at the triangle vertices. An example of a graphics system using the technique, for full-screen (rather than tile-based) rendering, is given in International patent application WO 96/36011 of The 3DO Company. In the system described, an application program creates a model in model space from triangular image primitives, with each triangle vertex having three spatial coordinates, four color values (R,G,B, and a blending factor A) and two coordinates (u,v) into a two-dimensional texture map. The application program loads a desired texture map into a texture buffer and transforms the model as desired.
Projecting the model into the image plane yields a homogeneity divisor w (related to depth value), by which all spatial vertex coordinates are divided to give homogenised spatial coordinates (u/w, v/w) into a hypothetical depth-adjusted texture space. The application program then passes vertex instruction lists to a triangle engine using per-vertex representations of x/w, y/w, u/w, v/w, and 1/w. The set-up procedure optimises the range of values for w that can be applied to the values of 1/w at the three vertices of a triangle, and block fixes not only the three 1/w values but also the values of u/w and v/w.
Whereas such conventional rendering processes each triangle sequentially, tile-based rendering assembles all triangles impacting a given region of the screen (a tile) and renders these, processing tiles sequentially. Tile-based rendering systems must therefore maintain the attributes for all triangles currently being processed (rather than just those for one triangle). Additionally, with incremental interpolation of attributes, such systems must be able to save and restore intermediate results for each triangle so that they can be used as start values for the next tile. This saving and restoration of attributes leads to an increase in memory bandwidth between off-chip attribute memory and on-chip attribute processing; using an on-chip cache helps, but the cache must be able to hold attributes for a reasonable fraction of the triangles currently being processed.
In order to determine which screen pixels are inside each triangle additional control values are calculated and incrementally interpolated along with the triangle attributes. A control value is maintained for each edge and is typically a multiple of the shortest distance from a point to the edge. Systems which perform anti-aliasing will explicitly set the multiple to unity to suit their internal anti-aliasing algorithm, but the inside-outside test requires only the sign of the control values to determine if a pixel is inside the triangle. Such control values are in effect additional attributes to be calculated, saved, restored and interpolated.
It is therefore an object of the present invention to reduce the number of attributes to be calculated, particularly but not exclusively in a tile-based renderer.
In accordance with the present invention there is provided an image processing method for rendering a two dimensional pixel image from a plurality of triangular image primitives to be projected onto an image plane, in which per-pixel attribute values, derived by interpolation from values held for the triangle vertices, are mapped onto respective pixels within the projected triangular primitives, characterised in that, for each triangle:
prior to projection, the triangle is parameterised with a respective two-dimensional coordinate system with the coordinate axes (s,t) concurrent with respective edges of the triangle and the origin coincident with the vertex between said edges; during projection, a generalised interpolation function is applied in terms of the parameterising coordinate system, determining parameter values at positions within the triangle in terms of the two-dimensional coordinate system; and, following projection, the determined parameter values at positions within the triangle determine contributions from the stored values for one or more attributes at each vertex, to give attribute values at each pixel; wherein corresponding per pixel attribute values from all triangles jointly determine an output color for each pixel.
As will become apparent from reading of the following exemplary embodiments, the per-primitive parameterisation in s and t provides noticeable benefits in terms of perspective correctness. By determination of the parameter values at positions within the triangles, the application of the various attributes stored for triangle vertices is considerably simplified.
Suitably, as part of the above method, a pixel may be tested to determine whether the center of the pixel lies inside or outside a triangle using perspective correct interpolants s/z, t/z and 1/z, where z is a depth value for the pixel. The value z suitably specifies the depth in terms of view space, although other depth relations (similar to the homogeneity divisor w of WO 96/36011) may be used. The particular benefit here is that all of the required variables are already available, resulting from the parameterisation operation.
For improved accuracy, and to anti-alias edges, the above test to determine location inside or outside a triangle may suitably be further performed at each of a plurality of sample points within a predetermined distance of the pixel center. Also, to avoid problems at intersecting primitives (described hereinafter), the line defined by the intersection of two triangles is preferably anti-aliased at each pixel using the inverse depth 1/z at said plurality of sample points: as before, this has benefit in that the required variables are already available.
Also in accordance with the present invention there is provided an image processing apparatus configured to render a two dimensional pixel image from data defining a plurality of triangular image primitives to be projected onto an image plane, the apparatus including interpolation means arranged to derive per-pixel attribute values from values held for the triangle vertices, and data handling means arranged to map said per-pixel attribute values onto respective pixels within the projected triangular primitives, characterised in that the apparatus further comprises: calculation means coupled to receive the data defining said triangular primitives, prior to projection, and arranged to parameterise each triangle with a respective two-dimensional coordinate system with the coordinate axes (s,t) concurrent with respective edges of the triangle and the origin coincident with the vertex between said edges; projection means operable to apply a generalised interpolation function to each triangle and in terms of the parameterising coordinate system, such as to derive parameter values at positions within a triangle in terms of said two-dimensional coordinate system; and pixel shading means configured to derive, from said determined parameter values at positions within the triangle, contributions from said stored values for one or more attributes at each vertex, such as to give attribute values at each pixel, and to combine per pixel attribute values from all triangles and output a per pixel color value.
Such apparatus may further comprise a storage means holding a plurality of data stacks, with each stack being associated with a respective pixel and holding entries identifying parameters of one or more triangles impacting the pixel: suitably, means may be provided to exclude from a stack any triangle parameters that would have no noticeable impact on the pixel appearance. Optionally, up to a predetermined number of said stack entries may be stored in an order determined by their respective depth values, and in order to avoid overflow problems as entries are discarded or candidates rejected, means may be provided for selectively transferring data from discarded or rejected candidate stack entries to extant stack entries.